package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/user/shoppingCart")
@Api("购物车控制类")
public class ShoppingCartController {
    /**
     * 购物车控制类
     */

    @Autowired
    private ShoppingCartService shoppingCartService;
    /**
     * 添加购物车接口
     */
    @PostMapping("/add")
    @ApiOperation("添加购物车接口")
    public Result addShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("添加购物车接口shoppingCartDTO:{}",shoppingCartDTO);
        shoppingCartService.addShoppingCart(shoppingCartDTO);
        return Result.success();
    }
    /**
     * 查询购物车接口
     */
    @GetMapping("/list")
    @ApiOperation("查询购物车接口")
    public Result<List<ShoppingCart>> queryShoppingCart(){
        log.info("查询购物车接口");
        List<ShoppingCart> list = shoppingCartService.queryShoppingCart();
        return Result.success(list);
    }
    /**
     * 清空购物车接口
     */
    @DeleteMapping("/clean")
    @ApiOperation("清空购物车接口")
    public Result cleanShoppingCart(){
        log.info("查询购物车接口");
        shoppingCartService.cleanShoppingCart();
        return Result.success();
    }
    /**
     * 删除购物车接口
     */
    @PostMapping("/sub")
    @ApiOperation("删除购物车接口")
    public Result deleteShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("删除购物车接口shoppingCartDTO:{}",shoppingCartDTO);
        shoppingCartService.deleteShoppingCart(shoppingCartDTO);
        return Result.success();
    }
}
